package 力扣刷题.两数相加;

import java.util.Arrays;
import java.util.HashMap;

class Solution {
    public int[] twoSum(int[] nums, int target) {
/*
        for(int i=0;i<nums.length;i++) {
            for(int j=i+1;j<nums.length;j++) {
                if(nums[i]+nums[j]==target) {
                    return new int[]{i,j};
                }
            }
        }
        return new int[]{};*/
        HashMap<Integer, Integer> hashMap=new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            int another_num = target-nums[i];
            if (hashMap.containsKey(another_num)) {
                return new int[]{hashMap.get(another_num),i};
            }
            hashMap.put(nums[i],i);
        }
        return null;
    }

    public static void main(String[] args) {
        System.out.println(Arrays.toString(new Solution().twoSum(new int[]{2, 7, 11, 15}, 9)));
        System.out.println("你好");
    }
}